//
//  BaseViewController.m
//  PropertyMananger
//
//  Created by bh on 16/12/20.
//  Copyright © 2016年 BH. All rights reserved.
//

#import "BaseViewController.h"

@interface BaseViewController ()

@end

@implementation BaseViewController



- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
    [self setOpenBack];
    
}

- (void)viewDidLoad {
    [super viewDidLoad];
   
    [self loadOrderNavigation];
    
    self.view.backgroundColor = [UIColor whiteColor];
    
    self.nextPage = 1;
    
    self.resultArr = [[NSMutableArray alloc]init];
    
}

-(void)loadOrderNavigation{
    self.view.backgroundColor = [UIColor whiteColor];
    self.navigationController.navigationBar.translucent = NO;
    self.tabBarController.tabBar.translucent = NO;
    [self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor whiteColor],NSForegroundColorAttributeName:[UIFont systemFontOfSize:25]}];
    
    //左按键
    UIButton * leftBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    leftBtn.frame = CGRectMake(0, 0, 20, 20);
    [leftBtn setImage:[UIImage imageNamed:@"ico_return"] forState:UIControlStateNormal];
    [leftBtn addTarget:self action:@selector(leftButtonClick) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem * leftItem = [[UIBarButtonItem alloc] initWithCustomView:leftBtn];
    self.navigationItem.leftBarButtonItem = leftItem;
}
#pragma mark - 返回按钮点击
-(void)leftButtonClick{
    
    [MBProgressHUD hideHUD];
    [self.navigationController popViewControllerAnimated:YES];
   
}
#pragma mark - 导航栏标题
- (void)initTitleViewName:(NSString *)titleName{
    
    //    导航栏中间文字
    self.titleLable = [[UILabel alloc] init];
    self.titleLable.frame = CGRectMake(0,0,100,25);
    //    self.titleLable.textColor = [UIColor colorWithHexString:@"#56bbed" alpha:1.0];
    self.titleLable.textColor = [UIColor whiteColor];
    self.titleLable.text = titleName;
    self.titleLabel.font = BHFont(16);
    self.titleLable.textAlignment = NSTextAlignmentCenter;
    self.navigationItem.titleView = self.titleLable;
}
#pragma mark - 导航栏左边按键
- (void)initRightUICustomButtonImageName:(NSString *)ImageName AndTitleName:(NSString *)titleName{
    
    self.leftCustomButton = [UIButton buttonWithType:UIButtonTypeCustom];
    self.leftCustomButton.frame = CGRectMake(0,0,32,32);
    [self.leftCustomButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [self.leftCustomButton setTitle:titleName forState:UIControlStateNormal];
    self.leftCustomButton.titleLabel.font = [UIFont systemFontOfSize:16];
    [self.leftCustomButton setImage:[UIImage imageNamed:ImageName] forState:UIControlStateNormal];
    [self.leftCustomButton addTarget:self action:@selector(rightButtonClick:) forControlEvents:UIControlEventTouchUpInside];
    
    UIBarButtonItem * rightButtonItem = [[UIBarButtonItem alloc] initWithCustomView:self.leftCustomButton];
    self.navigationItem.rightBarButtonItem = rightButtonItem;
}

#pragma mark - 导航栏右边按钮点击事件
- (void)rightButtonClick:(UIButton *)button{
    
    UIViewController * vc = [[UIViewController alloc]init];
    [self.navigationController pushViewController:vc animated:YES];
}
#pragma mark -  手势返回功能
- (void)setOpenBack{
    
    [self.navigationController.interactivePopGestureRecognizer setDelegate:self];
    BOOL isEnabled = self.navigationController.interactivePopGestureRecognizer.enabled;
    NSUInteger viewCount = self.navigationController.viewControllers.count;
    
    if(viewCount==1 && isEnabled)
        [self.navigationController.interactivePopGestureRecognizer setEnabled:NO];
    
    if(viewCount>1 && !isEnabled)
        [self.navigationController.interactivePopGestureRecognizer setEnabled:YES];
}
#pragma mark - tableView
- (void)initTableViewWithView:(UIView *)view frame:(CGRect)frame isGroup:(BOOL)isGroup
{
    if(isGroup)
        self.tableView = [[UITableView alloc] initWithFrame:frame  style:UITableViewStyleGrouped];
    else
        self.tableView = [[UITableView alloc] initWithFrame:frame  style:UITableViewStylePlain];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
    self.tableView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
    self.tableView.backgroundColor = [UIColor clearColor];
    self.tableView.userInteractionEnabled = true;
    UIView * footView = [[UIView alloc]init];
    view.backgroundColor = [UIColor whiteColor];
    self.tableView.tableFooterView = footView;
    
    [view addSubview:self.tableView];
}
//- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
//    
//    return 0;
//}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    return 0;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *CellIdentifier = @"tableviewCell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }
    return cell;
}

@end
